package com.fitc.treestructure;

import java.util.ArrayList;
import java.util.List;

public class Path extends ArrayList<Node>{
	private double _sd =-1;
	
	private void calcSd(){
		ArrayList<Integer> lengths = new ArrayList<Integer>();
		
		int[] wordLengths = new int[this.size()-1]; 
		
		for (Node n : this){
			int wordLength = n.getIdentifier().length();
			if (wordLength>0) lengths.add(wordLength); //get rid of zero length nodes
		}
		_sd = Stats.sd(lengths);
		
	}
	
	public double getSd(){
		if (_sd == -1) this.calcSd(); //i.e. not calculated yet
		return _sd;
	}
	
	@Override
	public String toString(){
		String str = "";
		
		for (Node n:this){
			str = str + n.getIdentifier() +" "; 
		}
		
		return str; 
	}
	
	public String[] toStringArray(){
		List<String> l = new ArrayList<String>(this.size());
		String BLANK = "";
		for (Node n : this){
			if (!n.getIdentifier().trim().equals(BLANK)){
				l.add(n.getIdentifier());
			}
		}
		return l.toArray(new String[0]);
	}
}
